/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package simhya.simengine.ode;
import org.apache.commons.math.ode.DerivativeException;
import org.apache.commons.math.ode.FirstOrderDifferentialEquations;
import simhya.model.flat.FlatModel;
import simhya.model.transition.AtomicReset;
import simhya.model.store.Function;
import simhya.model.store.Predicate;


/**
 *
 * @author luca
 */
public abstract class OdeFunction implements FirstOrderDifferentialEquations {
    private FlatModel model;

    Function [] rate;
    Predicate [] guard;
    Stoichiometry[][] stoich;
    int[] transitions;
    int dimension;
    int continuousTransitions;
    int totalTransitions;
    

    public OdeFunction(FlatModel model) {
        this.model = model;
        this.dimension = model.getStore().getVariablesReference().getNumberOfSymbols();
        this.continuousTransitions = model.getNumberOfContinuousTransitions(true);
        this.totalTransitions = model.getNumberOfTransitions();
        rate = model.getTransitionRates();
        guard = model.getTransitionGuards();
        stoich = new Stoichiometry[totalTransitions][];
        transitions = model.getListOfContinuousTransitionID(true);
        AtomicReset[][] resets = model.getTransitionResets();
        for (Integer j : transitions) {
            stoich[j] = new Stoichiometry[resets[j].length];
            for (int i=0;i<resets[j].length;i++) 
                stoich[j][i] = new Stoichiometry(resets[j][i].getUpdatedVariables().get(0),
                        resets[j][i].getConstantIncrement());
        }
    }

   

   

    public int getDimension() {
        return this.dimension;
    }



}


class Stoichiometry {
    public int variable;
    public double coefficient;

    public Stoichiometry(int variable, double coefficient) {
        this.variable = variable;
        this.coefficient = coefficient;
    }
}